package com.taotao.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.taotao.web.pojo.Item;
import com.taotao.web.pojo.ItemDesc;
import com.taotao.web.service.ItemDescService;
import com.taotao.web.service.ItemService;

@Controller
@RequestMapping("/item")
public class ItemController {
	
	@Autowired
	private ItemService itemService;
	@Autowired
	private ItemDescService itemDescService;
	/**
	 * 商品详情页面查询数据: 
	 * 参数: itemId
	 * 结果: item itemDesc
	 * @param itemId
	 * @return
	 */
	@GetMapping("{itemId}")
	public ModelAndView queryItemById(@PathVariable("itemId") Long itemId){
		Item item = itemService.queryById(itemId);
		ItemDesc itemDesc = itemDescService.queryByItemId(itemId);
		ModelAndView mv = new ModelAndView("item");
		mv.addObject("item", item);
		mv.addObject("itemDesc", itemDesc);
		return mv;
	}
	
}

